package day1_array.leetcode;

/**
 * 对撞指针判断回文串
 * @Author: yuisama
 * @Date: 2022/3/29 18:09
 * @Description:
 */
public class Num125_IsPalindrome {
    public boolean isPalindrome(String s) {
        if (s.length() == 1) {
            return true;
        }
        // 先将字符串的空格和大小写处理掉
        s = s.trim().toLowerCase();
        int l = 0;
        int r = s.length() - 1;
        while (l < r) {
            char left = s.charAt(l);
            char right = s.charAt(r);
            if (!Character.isLetterOrDigit(left)) {
                l ++;
                continue;
            }
            if (!Character.isLetterOrDigit(right)) {
                r --;
                continue;
            }
            if (left != right) {
                return false;
            }else {
                l ++;
                r --;
            }
        }
        return true;
    }
}
